<template>
    <div>
        <router-link class="header-abs" tag="div" to="/" v-show="showAbs">
            <div class="iconfont header-back">&#xe60a;</div>
        </router-link>
        <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
            景点详情
            <router-link to="/">
                <div class="iconfont header-fixed-back">&#xe60a;</div>
            </router-link>
        </div>
    </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      console.log('123')
      console.log(document.documentElement.scrollTop)
      const top = document.documentElement.scrollTop
      if (top > 37) {
        let opacity = top / 100
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {opacity}
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibies.styl';
    .header-abs
        position: absolute
        left: .1rem
        top: .1rem
        width: .6rem
        height: .6rem
        line-height: .6rem
        text-align: center
        border-radius: .6rem
        background: black
        z-index: 2
        .header-back
            color: #fff
            font-size: .3rem
    .header-fixed
        position fixed
        top: 0
        left 0
        right 0
        height :$headerHeight
        line-height :$headerHeight
        text-align :center
        color : #fff
        background :$bgColor
        font-size: .3rem
        z-index: 2
        .header-fixed-back
            position absolute
            top :0
            left :0
            font-size: .4rem
            width: .64rem
            text-align :center
            color: #fff
</style>
